package stone;

import static stone.Parser.rule;
import stone.ast.ClassBody;
import stone.ast.ClassStmnt;
import stone.ast.Dot;

public class ClassParser extends ClosureParser {
    Parser member = rule().or(def, simple);
    Parser classBody = rule(ClassBody.class).sep("{").option(member)
            .repeat(rule().sep(";", Token.EOL).option(member)).sep("}");
    Parser defClass = rule(ClassStmnt.class).sep("class").identifier(reserved)
            .option(rule().sep("extends").identifier(reserved)).ast(classBody);

    public ClassParser() {
        postfix.insertChoice(rule(Dot.class)).sep(".").identifier(reserved);
        program.insertChoice(defClass);
    }
}
